home *** CD-ROM | disk | FTP | other *** search
/ Speccy ClassiX 1998 / Speccy ClassiX 98.iso / amiga_system / the_aminet / dev / c / asyncio.lha / AsyncIO / src / CloseAsync.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-10  |  859 b   |  52 lines

  1. #include "async.h"
  2.  
  3. LibCall LONG
  4. CloseAsync( _REG( a0 ) struct AsyncFile *file )
  5. {
  6. #ifdef ASIO_NOEXTERNALS
  7.     struct ExecBase        *SysBase;
  8.     struct DosLibrary    *DOSBase;
  9. #endif
  10.     LONG    result;
  11.  
  12.     if( file )
  13.     {
  14. #ifdef ASIO_NOEXTERNALS
  15.         SysBase = file->af_SysBase;
  16.         DOSBase = file->af_DOSBase;
  17. #endif
  18.         result = AS_WaitPacket( file );
  19.  
  20.         if( result >= 0 )
  21.         {
  22.             if( !file->af_ReadMode )
  23.             {
  24.                 /* this will flush out any pending data in the write buffer */
  25.                 if( file->af_BufferSize > file->af_BytesLeft )
  26.                 {
  27.                     result = Write(
  28.                         file->af_File,
  29.                         file->af_Buffers[ file->af_CurrentBuf ],
  30.                         file->af_BufferSize - file->af_BytesLeft );
  31.                 }
  32.             }
  33.         }
  34.  
  35.         if( file->af_CloseFH )
  36.         {
  37.             Close( file->af_File );
  38.         }
  39.  
  40.         FreeVec(file);
  41.     }
  42.     else
  43.     {
  44. #ifndef ASIO_NOEXTERNALS
  45.         SetIoErr( ERROR_INVALID_LOCK );
  46. #endif
  47.         result = -1;
  48.     }
  49.  
  50.     return( result );
  51. }
  52.